var avatarUp, avatarUp1, avatarUp2 = "";

function iconTypeChange() {
    avatarUp = new $IconUpload("avatar0");
    avatarUp.initIcon();
    avatarUp1 = new $IconUpload("avatar1");
    avatarUp1.initIcon();
    avatarUp2 = new $IconUpload("avatar2");
    avatarUp2.initIcon();
}

function updateUploadIcons() {
    var reservationsId = document.getElementById("reservationsId").value;
    var customerId = document.getElementById("customerId").value;
    var doctor = document.getElementById("doctor").value;
    var toothPosition = "";
    if (doctor == null || doctor == "") {
        doctor = "doctor"
    }
    var toothPositionA = document.getElementById("leftUp").innerHTML;
    var toothPositionB = document.getElementById("rightUp").innerHTML;
    var toothPositionC = document.getElementById("leftDown").innerHTML;
    var toothPositionD = document.getElementById("rightDown").innerHTML;
    if (toothPositionA.length <= 0 && toothPositionB.length <= 0 && toothPositionC.length <= 0 && toothPositionD.length <= 0) {
        Feng.error("牙位不能为空！");
        return false;
    }
    if (toothPositionA.length > 0) {
        toothPosition = "A" + toothPositionA;
    } else if (toothPositionB.length > 0) {
        toothPosition = "B" + toothPositionB;
    } else if (toothPositionC.length > 0) {
        toothPosition = "C" + toothPositionC;
    } else if (toothPositionD.length > 0) {
        toothPosition = "D" + toothPositionD;
    }
    var payServiceId = document.getElementById("payServiceId").value;
    if (payServiceId == null || payServiceId == "") {
        payServiceId = "payServiceId"
    }
    var remarks = document.getElementById("remarks").value;
    if (remarks == null || remarks == "") {
        remarks = "remarks"
    }
    var finnallyTime = document.getElementById("finnallyTime").value;
    var num = document.getElementById("num").value;
    var cri = payServiceId + "," + customerId + "," + reservationsId + "," + remarks + "," + finnallyTime + "," + doctor + "," + toothPosition + "," + num;
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/updateUploadIcons",
        type: "post",
        data: {"cri": cri},
        success: function (data) {
            if ('hint' == data) {
                alert('只能上传对应类型的一张照片，请删除多余的照片!');
            } else if ('ps' == data) {
                alert('请选择图片!');
            } else {
                Feng.success("提交成功!");
                window.parent.QualityAssurancesByone.table.refresh();
                parent.layer.close(parent.layer.getFrameIndex(window.name));
            }
        },
        error: function (data) {
            alert('没有权限，请联系管理员!');
        }
    });
};

$(function () {
    var payServiceId = $("#payServiceIdValue").val();
    var remarks = $("#remarksValue").val();
    var doctor = $("#doctorValue").val();
    var finnallyTime = $("#finnallyTimeValue").val();
    var toothPosition = $("#toothPositionValue").val();
    var one = toothPosition.substring(0,1);
    var two = toothPosition.substring(1,2);
    if(remarks != ""){$("#remarks").val(remarks)}
    if(one == "A"){$("#leftUp").html(two)}else if(one == "B"){$("#rightUp").html(two)}else if(one == "C"){$("#leftDown").html(two)}else if(one == "D"){$("#rightDown").html(two)}
    if(payServiceId != ""){$("#payServiceId option[value='" + payServiceId + "']").attr("selected", "selected");}
    if(doctor != ""){$("#doctor option[value='"+doctor+"']").attr("selected", "selected");}
    if(finnallyTime != ""){$("#finnallyTime option[value='"+finnallyTime+"']").attr("selected", "selected");}
    iconTypeChange();
});
